package com.heima.domain.pojo;

import lombok.Data;

@Data
public class Result {
    private String msg;
    private int code;
    private Object data;

    // 默认成功结果
    public static Result success() {
        Result result = new Result();
        result.code = 200;
        result.msg = "success";
        return result;
    }

    // 带数据的成功结果
    public static Result success(Object data) {
        Result result = new Result();
        result.code = 200;
        result.msg = "success";
        result.data = data;
        return result;
    }

    // 默认失败结果
    public static Result error() {
        Result result = new Result();
        result.code = 500;
        result.msg = "error";
        return result;
    }

    // 自定义错误信息的失败结果
    public static Result error(String msg) {
        Result result = new Result();
        result.code = 500;
        result.msg = msg;
        return result;
    }

    // 自定义错误码和信息的失败结果
    public static Result error(int code, String msg) {
        Result result = new Result();
        result.code = code;
        result.msg = msg;
        return result;
    }
}

